package com.ruitu.health_2.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.makeramen.roundedimageview.RoundedImageView;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.health_2.R;
import com.ruitu.health_2.ui.activity.ProductDetailActivity;
import com.ruitu.router_module.activity.PhotoCheckActivity;
import com.ruitu.router_module.bean.product.Comment;
import com.ruitu.router_module.util.GlideUtil;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

// 评价列表adapter
public class EvaluateListAdapter extends ListBaseAdapter<Comment> {

    public EvaluateListAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_evaluate_list;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        RoundedImageView iv_header = holder.getView(R.id.iv_header);
        TextView tv_name = holder.getView(R.id.tv_name);
        TextView tv_score = holder.getView(R.id.tv_score);
        TextView tv_time = holder.getView(R.id.tv_time);
        TextView tv_content = holder.getView(R.id.tv_content);
        RecyclerView rcv_img = holder.getView(R.id.rcv_img);

        Comment comment = mDataList.get(position);

        tv_name.setText(comment.getMemberNickName());
        tv_score.setText(comment.getStar() + "分");
        tv_time.setText(comment.getCreateTime());
        tv_content.setText(comment.getContent());
        GlideUtil.loadImg(comment.getMemberIcon(), iv_header);

        // 评价的图片
        rcv_img.setVisibility(View.GONE);
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);

        EvaImgAdapter adapter = new EvaImgAdapter(mContext);
        rcv_img.setLayoutManager(manager);
        rcv_img.setAdapter(adapter);

        List<String> imgList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            imgList.add("");
        }
        adapter.setDataList(imgList);
    }

    private class EvaImgAdapter extends ListBaseAdapter<String> {

        public EvaImgAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_eva_image;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, final int position) {
            ImageView iv_pro = holder.getView(R.id.iv_pro);

            GlideUtil.loadImg("", iv_pro);

            iv_pro.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //点击查看商品图片
                    Intent intent = new Intent(mContext, PhotoCheckActivity.class);
                    intent.putExtra("position", position);
                    ArrayList<String> imgPaths = new ArrayList<>();
//            for (Evaluate.EvaluateImg i : mDataList) {//封装图片路径,传到图片查看页面
//                imgPaths.add(Config.BASE_URL + i.getUrl());
//            }
                    intent.putExtra("list", imgPaths);
                    mContext.startActivity(intent);
                    ((ProductDetailActivity) mContext).overridePendingTransition(
                            R.anim.fade_in, R.anim.fade_out);
                }
            });
        }
    }
}
